<template>
  <div class="app-container">
    <!-- banner列表 -->
    <el-table v-loading="listLoading" :data="list"
              border
              fit
              highlight-current-row>

      <el-table-column
        label="序号"
        width="60"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="仓库名"/>
      <el-table-column prop="fullLoc" label="仓库地址"/>
      <el-table-column prop="supervisor" label="负责人"/>
      <el-table-column prop="tel" label="联系人电话"/>

      <el-table-column  width="230" align="center">
        <template slot-scope="scope">
          <router-link :to="'/goods-addStock?id='+scope.row.id">
            <el-button type="primary" size="mini">添加库存</el-button>
          </router-link>
        </template>
      </el-table-column>

    </el-table>

    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
      style="padding: 30px 0; text-align: center;"
      layout="sizes, prev, pager, next, jumper, ->, total, slot"
      @current-change="fetchData"
      @size-change="changeSize"
    />

  </div>
</template>

<script>
export default {
  name: "warehouse",
  data(){
    return{
      total: 0, // 数据库中的总记录数
      page :1,
      limit: 5,
      list: null,
      listLoading: true, // 数据是否正在加载
    }
  },
  created() {
    this.fetchData(1)
  },
  methods:{
    fetchData(page = 1) {
      this.page = page
      this.$http({
        url: this.$http.adornUrl(`/product/warehouse/list/${page}/${this.limit}`),
        method: 'get'
      }).then(({data}) => {
        this.list = data.data.records
        this.total = data.data.total
        this.listLoading = false
      })

    },
    changeSize(val) {
      this.limit = val
      this.page = 1
      this.fetchData(1)
    },
  }

}
</script>

<style scoped>

</style>
